package com.arkisv.log.mq.receiver;

import com.arkisv.common.model.StepLog;
import com.arkisv.log.util.Global;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

/**
 * 步骤日志接收器
 * Created by fb on 2017/1/23.
 */
@Component
public class StepLogReceiver implements MessageListener {
    @Override
    @JmsListener(destination = "step_log")
    public void onMessage(Message message) {
        ObjectMessage om = (ObjectMessage) message;
        try {
            StepLog stepLog = (StepLog) om.getObject();
            if(stepLog == null || stepLog.getEventId() == null) {
                return;
            }
            // 批量插入日志
            Global.batchAddStepLog(stepLog);
            
//            stepLogDao.insertSelective(stepLog);
        } catch (JMSException e) {
            e.printStackTrace();
        }

    }
}